package com.changcheng.controller;
import com.changcheng.service.ArticleTypeService;
import com.changcheng.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@Api(tags = "文章类型")
@RestController
@RequestMapping("/articleType")
public class ArticleTypeController {
    @Autowired
    ArticleTypeService articleTypeService;
    @GetMapping({"selectAll"})
    //查询所有文章类型
    @ApiOperation("查询所有文章类型")
    public List<String> index(){
        List<String> allArticleType = articleTypeService.findAllArticleType();
        return allArticleType;
    }


    @PostMapping("/addArticleType")
    @ApiOperation("新增文章类型")
    //新增文章类型
    public R add(String name){
        //判断文章类型是否存在
        boolean at = articleTypeService.findArticleType(name);
        if(at == true){
           return R.error("文章类型已经存在！");
        }else
        {
            articleTypeService.add(name);
            return R.ok("新增成功！");
        }
    }
    //修改文章类型
    @PutMapping("/updateArticleType")
    @ApiOperation("修改文章类型")
    public R update(String name){
        articleTypeService.update(name);
        return R.ok("修改成功");
    }
    //删除文章类型
    @DeleteMapping("/deleteArticleType")
    @ApiOperation("删除文章类型")
    public R delete(String name){
        articleTypeService.delete(name);
        return R.ok("删除成功");
    }
}
